package model;

/**
 * Street is a type of field where the rent is determined by the number of houses the user has on the field.
 * @author Group 20
 *
 */

public class Street extends Ownable  
{
	private int rent, rentOneHouse, rentTwoHouses, rentThreeHouses, rentFourHouses, rentHotel, housePrice;
	private int numOfHouses = 0, numOfHotels = 0;
	
	
	private String groupColor;
		
	/**
	 * Constructor
	 * @param number: Field number
	 * @param name: Field name
	 * @param description: Field description
	 * @param price: Field price
	 * @param rent: Field rent
	 * @param rentOneHouse: Field rent with one house
	 * @param rentTwoHouses: Field rent with two houses
	 * @param rentThreeHouses: Field rent with three houses
	 * @param rentFourHouses: Field rent with four houses
	 * @param rentHotel: Field rent with a hotel
	 * @param housePrice: Field house price
	 * @param groupColor: Field group color
	 */
	public Street(int number, String name, String description, int price, int rent, int rentOneHouse, int rentTwoHouses, int rentThreeHouses, int rentFourHouses, int rentHotel, int housePrice, String groupColor) 
	{
		super(number, name, description, price);
		this.rent = rent;
		this.rentOneHouse = rentOneHouse;
		this.rentTwoHouses = rentTwoHouses;
		this.rentThreeHouses = rentThreeHouses;
		this.rentFourHouses = rentFourHouses;
		this.rentHotel = rentHotel;
		this.housePrice = housePrice;
		this.groupColor = groupColor;
	}
	
	

	/**
	 * Returns whether or not the street is pawned
	 */
	public boolean isPawned() 
	{
		return pawned;
	}


	/**
	 * Returns the group color
	 * @return string: color of street
	 */
	public String getGroupColor() {
		return groupColor;
	}



	/**
	 * returns the rent.
	 */
	@Override
	public int rent() 
	{
		return rent;
	}

	/**
	 * Returns whether or not the player has enough money for the rent on the field, and withdraws it if he has.
	 */
	@Override
	public boolean landOnField(Player player, int dicesSum, int numOfFieldTypeOwned) 
	{
		
		
		if (owner != null)
		{
			if (owner.equals(player) || pawned)
				this.payment = 0;
			else
			{

				if(numOfHouses == 1)
					payment = rentOneHouse;
				else if(numOfHouses == 2)
					payment = rentTwoHouses;
				else if(numOfHouses == 3)
					payment = rentThreeHouses;
				else if(numOfHouses == 4)
					payment = rentFourHouses;
				else if(numOfHotels == 1)
					payment = rentHotel;
				else
					payment = rent;
			}
				
			

			if (player.getBalance()>=payment)
			{
				player.withdraw(payment);
				owner.deposit(payment);
				return true;
			}

			return false;
		}
		return true;
	}

	/**
	 * Increases the amount of houses on the field and determine whether or not the next house is a hotel.
	 */
	public void buyHouse()
	{
		numOfHouses++;
		
		if (numOfHouses == 5)
		{
			numOfHotels = 1;
			numOfHouses = 0;
		}
	}
	
	/**
	 * returns whether or not the player has a hotel on the field.
	 * @return boolean value
	 */
	public boolean hasHotel()
	{
		return (numOfHotels() > 0);
	}
	
	/**
	 * Decreases the amount of houses on the field and determines if a hotel should be made into 4 houses.
	 */
	public void sellHouse()
	{
		numOfHouses--;
		
		if (numOfHotels == 1)
		{
			numOfHotels = 0;
			numOfHouses = 4;
		}
	}
		
	/**
	 * Returns the amount of houses
	 * @return numOfHouses: number of houses
	 */
	public int getNumOfHouses() {
		return numOfHouses;
	}

	/**
	 * returns the amount of hotels.
	 * @return numOfHotels: number of hotels
	 */
	public int getNumOfHotels() {
		return numOfHotels;
	}

	/**
	 * returns the rent
	 * @return rent: Fields rent value
	 */
	public int getRent() 
	{
		return rent;
	}

	/**
	 * Returns the rent for one house
	 * @return rentOneHouse: Rent value with one house
	 */
	public int getRentOneHouse() {
		return rentOneHouse;
	}

	/**
	 * Returns the rent for two houses
	 * @return rentTwoHouses: rent value with two houses
	 */
	public int getRentTwoHouses() {
		return rentTwoHouses;
	}

	/**
	 * Returns the rent for three houses
	 * @return rentThreeHouses: rent value with three houses
	 */
	public int getRentThreeHouses() {
		return rentThreeHouses;
	}

	/**
	 * Returns the rent for four houses
	 * @return rentFourHouses: rent value with four houses
	 */
	public int getRentFourHouses() {
		return rentFourHouses;
	}

	/**
	 * Returns the rent for a hotel
	 * @return rentHotel: rent value with a hotel
	 */
	public int getRentHotel() {
		return rentHotel;
	}


	/**
	 * Returns the price for a house
	 * @return housePrice: price of a house
	 */
	public int getHousePrice() {
		return housePrice;
	}

	
	/**
	 * toString Method
	 */
	@Override
	public String toString() {
		return "Street [rent=" + rent + ", rentOneHouse=" + rentOneHouse
				+ ", rentTwoHouses=" + rentTwoHouses + ", rentThreeHouses="
				+ rentThreeHouses + ", rentFourHouses=" + rentFourHouses
				+ ", rentHotel=" + rentHotel + ", housePrice=" + housePrice + ", groupColor=" + groupColor
				+ "]";
	}

	/**
	 * Calculates the value of a street with it's houses and hotels
	 */
	@Override
	public int valueOfAssets() 
	{
		return (price + (numOfHotels * housePrice*5) + (numOfHouses * housePrice));
	}

	/**
	 * Returns the number of houses.
	 */
	@Override
	public int numOfHouses() 
	{
		return numOfHouses;
	}
	
	/**
	 * Sets the number of houses
	 */
	public void setNumOfHouses(int numOfHouses) {
		this.numOfHouses = numOfHouses;
	}

	/**
	 * Returns the number of hotels
	 */
	@Override
	public int numOfHotels() {
		return numOfHotels;
	}

	

	
	
}
